﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using Model.District;
using Newtonsoft.Json;

namespace Lian
{
    public partial class WebForm11 : System.Web.UI.Page
    {
        private District districtList;
        public WebForm11() {
            //将district.json转换为代码
            using (FileStream stream = new FileStream(Server.MapPath("~/App_Data/district.json"),FileMode.Open)) {
                StreamReader streamReader = new StreamReader(stream, Encoding.Default);
                string json = streamReader.ReadToEnd();
                districtList = JsonConvert.DeserializeObject<District>(json);
            }
        }

        public void aa() {
            ddlProvince.DataSource = districtList.Provinces;
            ddlProvince.DataTextField = "ProvinceName";
            ddlProvince.DataValueField = "ProvinceName";
            ddlProvince.DataBind();
        }

        public void bb(string bbb) {
            ddlCity.DataSource = districtList.Provinces.SingleOrDefault(a => a.ProvinceName == bbb).Citys;
            ddlCity.DataTextField = "CityName";
            ddlCity.DataValueField = "CityName";
            ddlCity.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                aa();
            }
            
        }

        protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
        {
            bb(ddlProvince.SelectedValue);
        }
    }
}